# 使用udp模拟客服回复
from socket import socket, AF_INET, SOCK_DGRAM
udp_server = socket(AF_INET, SOCK_DGRAM)

ip = '127.0.0.1'
port = 8087
udp_server.bind((ip, port))

while True:
    u,addr = udp_server.recvfrom(1024)
    r = u.decode('utf-8')
    print('接收的数据为：', r)
    if r == 'bye' :
        break
    aw = input('请输入回复的数据：')
    udp_server.sendto(aw.encode('utf-8'),addr)


udp_server.close()

